import type { User, UserProfile } from "@/types/data";
import type { ProfileAction } from "@/types/store";
type ProfileState = {
  user: User;
  userProfile: UserProfile;
};
// 定义 UserProfile 默认值
const defaultUserProfile: UserProfile = {
  mobile: "",
  birthday: "",
  intro: "",
  id: "",
  photo: "",
  name: "",
  gender: 0,
};
const initialState = {
  user: {},
  userProfile: {},
} as ProfileState;

const profile = (state = initialState, action: ProfileAction): ProfileState => {
  switch (action.type as string) {
    case "profile/getUser":
      return {
        ...state,
        user: action.payload,
      };
    case "profile/getUserProfile":
      return {
        ...state,
        userProfile: defaultUserProfile,
      };
    case "profile/update":
      return {
        ...state,
        userProfile: {
          ...state.userProfile,
          ...action.payload,
        },
      };
    default:
      return state;
  }
};

export default profile;
